package com.app.business.web.uni;

import com.app.business.model.CarLot;
import com.app.business.model.House;
import com.app.business.service.uni.AppCarLotService;

import com.app.system.jpa.PageBean;
import com.app.system.permission.service.DataDictService;
import com.app.system.utils.CollectionUtils;
import com.app.system.utils.dataType.IntegerUtils;
import com.app.system.utils.dataType.StringUtils;
import com.app.system.utils.page.UViewUiUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@SuppressWarnings("all")
@RequestMapping(value = "/app/carLot/*")
public class AppCarLotController {
    @Autowired
    private AppCarLotService appCarLotService;
    @Autowired
    private DataDictService dataDictService;

    /**
     * 数据查询列表
     *
     * @param request
     * @return
     */
    @RequestMapping("carLotList")
    public Map carLotList(HttpServletRequest request) {
        //通过数据字典配置得到相应展示信息
        Map phoneInfoMap = dataDictService.getMapByParentNameForName_Value("手机端公示信息配置");
        String zsProjectIdStr = phoneInfoMap.get("征收项目ID").toString();//征收项目id list
        String azProjectIdStr = phoneInfoMap.get("安置项目ID").toString();//安置项目id list

        List<Map> listData = Lists.newArrayList();
        PageBean<CarLot> carLotPageBean = this.appCarLotService.getCarLotList(request,azProjectIdStr);
        Map<String, String> carLotTypeMap = dataDictService.getMapByParentNameForValue_Name("车位类型");
        Map<String, String> carLotStatusMap = dataDictService.getMapByParentNameForValue_Name("房源状态");
        Map houseStatusMap = this.dataDictService.getMapByParentNameForValue_Color("手机端房源状态");

        List<CarLot> carLotList = carLotPageBean.getDatas();
        if (CollectionUtils.isNotEmpty(carLotList)) {
            for (CarLot carLot : carLotList) {
                Map<String, Object> item = Maps.newHashMap();
                item.put("id", carLot.getId());
                item.put("buildNum", StringUtils.getNotNull(carLot.getBuildNum()));
                item.put("floor", StringUtils.getNotNull(carLot.getFloor().toString()));
                item.put("houseNum", StringUtils.getNotNull(carLot.getHouseNum()));
                item.put("buildArea", StringUtils.getNotNull(carLot.getBuildArea().toString()));
                item.put("style", "background-color:" + houseStatusMap.get(String.valueOf(carLot.getHouseStatus()))+ ";border-radius: 8px;");
                item.put("carLotType", carLotTypeMap.get(IntegerUtils.getNotNull(carLot.getCarLotType())));
                item.put("carLotTypeBtn", IntegerUtils.getNotNull(carLot.getCarLotType()) == 1 ? "u-type-info" : "u-type-primary");
                item.put("carLotTypeToString", StringUtils.getNotNull(carLotTypeMap.get(IntegerUtils.getNotNull(carLot.getCarLotType()) + "")));

                item.put("carLotStatus", carLotStatusMap.get(IntegerUtils.getNotNull(carLot.getHouseStatus())));
                item.put("carLotStatusBtn", IntegerUtils.getNotNull(carLot.getHouseStatus()) == 1 ? "u-type-info" : "u-type-primary");
                item.put("carLotStatusToString", StringUtils.getNotNull(carLotStatusMap.get(IntegerUtils.getNotNull(carLot.getHouseStatus()) + "")));

                listData.add(item);
            }
        }
        return UViewUiUtils.page(carLotPageBean, listData);
    }

}
